﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace MEMDB
{
    public partial class DeleteDatabase : Form
    {
        SQLConnection m_conn;
        bool isSuccessful = false;
        public DeleteDatabase(string DBNameList, SQLConnection con)
        {
            InitializeComponent();
            m_conn = con;
            string[] dbNames = DBNameList.Split('&');
            for (int i = 0; i < dbNames.Length; ++ i)
            {
                if (!dbNames[i].Equals(""))
                {
                    ListViewItem item = new ListViewItem();
                    item.Text = dbNames[i];
                    item.ImageIndex = 0;
                    this.DBNamelistlistView1.Items.Add(item);
                }
            }
            
        }


        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void deleteButton_Click(object sender, EventArgs e)
        {
            string strCommand = "nodb " + this.DBNamelistlistView1.SelectedItems[0].Text.Trim() + ";" ;
            SQLCommand cmd = new SQLCommand(strCommand, m_conn);

            //m_conn.Open();

            try
            {
                cmd.ExecuteNonQuery();
            }
            catch (SQLException ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message);
                return;
            }

            System.Windows.Forms.MessageBox.Show("删除数据库成功!");
            isSuccessful = true;
            this.Close();
        }

        public bool Successful
        {
            get
            {
                return isSuccessful;
            }
        }

        private void DBNamelistlistView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
        {
            if (DBNamelistlistView1.SelectedItems.Count != 0)
                deleteButton.Enabled = true;
            else
                deleteButton.Enabled = false;
        }

        private void DeleteDatabase_Load(object sender, EventArgs e)
        {

        }
    }
}
